package edu.tsinghua.ddb.util;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Event implements EventList {
	private final static Map<Integer, Set<EventListenerEx>> map = new HashMap<Integer, Set<EventListenerEx>>();

	public static void fire(int event, Object param) {
		for (EventListenerEx el : map.get(event))
			el.fire(param);
	}

	public static void register(int event, EventListenerEx el) {
		Set<EventListenerEx> s = map.get(event);
		if (s == null) {
			s = new HashSet<EventListenerEx>();
			map.put(event, s);
		}
		s.add(el);
	}

	public static void unregister(int event, EventListenerEx el) {
		Set<EventListenerEx> s = map.get(event);
		if (s != null) {
			s.remove(el);
		}
	}
}

interface EventList {
	int LOST_CONNECTION = 1;
}